package com.liaoban.app.ui.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.liaoban.app.R;
import com.liaoban.app.api.type.request.BindReq;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.helper.ToastHelper;
import com.liaoban.app.ui.base.BaseToolbarActivity;
import com.liaoban.app.widget.MyTextWatcher;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ybc on 2018/8/9 0009.
 * 绑定支付宝
 */
public class BindPayActivity extends BaseToolbarActivity {
    @BindView(R.id.et_account)
    EditText etAccount;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;

    @Override
    protected String getNewTitle() {
        return "绑定支付宝";
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_bind_pay;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initListener();
    }

    private void initListener() {
        MyTextWatcher myTextWatcher = new MyTextWatcher(() -> {
            if (!TextUtils.isEmpty(etAccount.getText().toString()) &&
                    !TextUtils.isEmpty(etName.getText().toString())) {
                tvSubmit.setEnabled(true);
                tvSubmit.setBackgroundResource(R.drawable.shape_yellow);
            } else {
                tvSubmit.setEnabled(false);
                tvSubmit.setBackgroundResource(R.drawable.shape_line);
            }
        });
        etAccount.addTextChangedListener(myTextWatcher);
        etName.addTextChangedListener(myTextWatcher);
    }

    @OnClick(R.id.tv_submit)
    public void onViewClicked() {
        showRunningDialog();
        BindReq bindReq = new BindReq();
        bindReq.setRealname(etName.getText().toString().trim());
        bindReq.setAlipay_id(etAccount.getText().toString().trim());
        startTask(CommonBiz.getInstance().bangding(bindReq), objectBaseResponse -> {
            ToastHelper.show(this, objectBaseResponse.msg);
            if (1 == objectBaseResponse.code) {
                finish();
            }
        });
    }
}
